package org.example.gradleadmin.service.impl;

import com.github.pagehelper.Page;
import gradle.common.core.utils.SortUtil;
import gradle.mybatis.common.response.ApiResponse;
import gradle.mybatis.common.utils.PageUtil;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.example.gradleadmin.mapper.SystemUserMapper;
import org.example.gradleadmin.model.dto.SystemUserQueryPageDto;
import org.example.gradleadmin.model.vo.SystemUserPageVo;
import org.example.gradleadmin.service.SystemUserService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户管理服务接口 实现类
 *
 * @author 1141193930@qq.com
 */
@Slf4j
@Service
public class SystemUserServiceImpl implements SystemUserService {

    @Resource
    private SystemUserMapper systemUserMapper;


    /**
     * 查询用户列表
     *
     * @param queryDto 查询条件
     * @return 用户分页视图Vo
     */
    @Override
    public ApiResponse<List<SystemUserPageVo>> listPage(SystemUserQueryPageDto queryDto) {
        //排序
        String sortStr = SortUtil.getSortStr(queryDto.getSort(), "u.create_time", "u.", SystemUserPageVo.class);
        //分页
        Page<List<SystemUserPageVo>> page = PageUtil.startPage(queryDto.getPageNum(), queryDto.getPageSize(), sortStr);
        //查询
        List<SystemUserPageVo> listPage = systemUserMapper.listPage(queryDto);

        return ApiResponse.success(listPage, page);
    }
}
